package com.ilop.siteraudio.data.util;

import com.ilop.siteraudio.data.bean.ReportBean;
import com.ilop.siteraudio.data.manage.CommonDaoUtils;
import com.ilop.siteraudio.data.manage.DaoManager;
import com.ilop.siteraudio.greendao.ReportBeanDao;

/**
 * @author skygge
 * @date 2021/2/17.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：
 */
public class ReportDaoUtil {

    private volatile static ReportDaoUtil instance = null;
    private final CommonDaoUtils<ReportBean> mReportUtils;
    private final ReportBeanDao mReportDao;

    public static ReportDaoUtil getInstance(){
        if (instance == null){
            synchronized (ReportDaoUtil.class){
                if (instance == null){
                    instance = new ReportDaoUtil();
                }
            }
        }
        return instance;
    }

    private ReportDaoUtil() {
        DaoManager mManager = DaoManager.getInstance();
        mReportDao = mManager.getDaoSession().getReportBeanDao();
        mReportUtils = new CommonDaoUtils(ReportBean.class, mReportDao);
    }

    public CommonDaoUtils<ReportBean> getReportDao(){
        return mReportUtils;
    }

    public ReportBean getReportById(long recordId) {
        return mReportDao.queryBuilder()
                .where(ReportBeanDao.Properties.ReportId.eq(recordId))
                .orderDesc(ReportBeanDao.Properties.ReportId)
                .unique();
    }
}
